<template>
  <a-grid-item :span="{xs: 1, sm: 2, md: 12}">
    <a-collapse :default-active-key="['1']" class="g-collapse">
      <a-collapse-item header="销售成本费用列表" key="1">
        <ma-crud ref="crudRef" :columns="columns" :options="options" :scrollbar="true">
          <template #fee_type="{ record }">

            {{getDictData('fee_type',record.fee_type)}} {{record.unit_amount  }}/{{getDictData('unit',record.unit) }} 
            
          </template>
        </ma-crud>
      </a-collapse-item>
    </a-collapse>
  </a-grid-item>
</template>
<script setup>

import {computed, inject, ref,reactive,h} from "vue";
import cost from "@/api/finance/cost.js";
import dictHelp from "@/utils/dicthelp.js";
import {Message} from "@arco-design/web-vue";
const crudRef = ref()
const parentCrudRef = inject('crudRef')
const record = inject('record')
const options = ref({
  showTools: false,
  // 默认统一设置列宽度
  columnWidth: 0,
  // tableLayoutFixed: true,
  pk: 'supplier_fee_id',
  api: cost.getList,
  requestParams: {
    bonus_bill_id: record.value.id,
  }
})
const getDictData = (key, value) => {
  let label = ''
  let dict = crudRef.value.getColumnService().dicts[key];
  if(dict !== undefined && dict.length > 0){
        dict.map(i => {
          if (value == i.value) {
            label = i.label
          }
        })
  }
  return label
}
const columns = reactive([
  {
      title: "业务时间",
      dataIndex: "business_at",
      formType: "input",
  },
  {
      title: "运单号",
      dataIndex: "shipment.shipment_no",
      formType: "input",
  },
  {
      title: "用户",
      dataIndex: "user_id",
      formType: "select",
      dict:dictHelp.customer,
  },
  {
      title: "费用类型",
      dataIndex: "fee_type",
      formType: "select",
      dict: {
        url: 'finance/feeType/list',
        props: {label: 'fee_name', value: 'id'} ,
        translation: true,
        params: {
          select: 'id,fee_name',
        }
      },
  },
  {
    title: "单位",
    dataIndex: "unit",
    formType: "select",
    hide:true,
    commonRules: {
      required: true,
      message: "请输入单位"
    },
    dict: {
      data: [
        { label: "KG", value: 1 },
        { label: "立方", value: 2 },
        { label: "票", value: 3},
        ],
      translation: true,
    },
  },
  {
      title: "金额/币种",
      dataIndex: "amount",
      customRender: ({record}) => {
        return record.amount + '/' + record.currency
      }
  },
  {
      title: "本币金额/币种",
      dataIndex: "local_amount",
      customRender: ({record}) => {
        return record.local_amount + '/' + record.local_currency
      }
  },
  {
    title: "描述",
    dataIndex: "memo",
  },
  {
    title: "备注",
    dataIndex: "remark",
  },
])
</script>